import axios from 'axios'



// 创建统一的url
axios.defaults.baseURL = 'http://43.138.186.111:8082/sgudp'
//axios.defaults.baseURL = 'http://localhost:8082/sgudp'
// 数据格式为json,下载文件要改
axios.defaults.headers.post['Content-Type'] = 'application/json'
// 下载文件
// axio.defaults.headers.post['Content-Type'] = 'multipart/form-data';
// 设置cross跨域 并设置访问权限 允许跨域携带cookie信息

axios.defaults.withCredentials = true


// 拦截器
axios.interceptors.request.use(
  config => {
    // 判断是都否有token,有则加进请求头
    if (localStorage.getItem('Authorization')) {
      config.headers.Authorization = localStorage.getItem('Authorization')
      console.log(localStorage.getItem('Authorization'))
    }
    return config
  },
  err => {
    console.log(localStorage.getItem('Authorization'))
    return Promise.reject(err)
  }
)

export default axios
